#ifndef __LUA_ENGINE_H__
#define __LUA_ENGINE_H__
#include "lua.hpp"
#include <vector>

class ILuaBind{//lua module interface
public:
	virtual void BindModule(lua_State *L) = 0;//interface to bind module
	virtual void UnbindModule(lua_State *L) = 0;//interface to unbind module
};

struct LuaParam;

class LuaEngine{
public:
	static LuaEngine *getInstance(){
		return instance_ptr;
	}
	static LuaEngine *create(ILuaBind *bind = 0){
		if(!instance_ptr){
			instance_ptr = new LuaEngine();
			if(bind){
				instance_ptr->bindModule(bind);
			}
		}
		return instance_ptr;
	}
	static void release(){
		if(instance_ptr){
			delete instance_ptr;
			instance_ptr = 0;
		}
	}
	LuaEngine();
	virtual ~LuaEngine();
public:
	int runLuaFunction(const char *name,LuaParam *in = 0,int i_count = 0,LuaParam *out = 0,int o_count =0);
	int loadString(const char *str);
	int loadData(const char *data,int len,const char *msg = "load...");
	int runFile(const char *fname);
	int bindModule(ILuaBind *bind);
protected:
	lua_State *m_state;
	std::vector<ILuaBind *> m_modules;
	static LuaEngine *instance_ptr; 
};

#endif